package com.mysqlconn;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @author wzm
 * @create 2023-06-12 15:47
 */
//通过外部配置文件获取连接
public class Conn02 {
    public static void main(String[] args) throws Exception {
        //从properties中读取配置文件信息
        //使用流的形式读取配置信息
        InputStream is = Conn02.class.getClassLoader().getResourceAsStream("jdbc.properties");

        //用来存储 读取的properties
        Properties properties = new Properties();
        properties.load(is);
        System.out.println("properties = " + properties);

        //从properties中获取到每个需要的信息
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driverClass = properties.getProperty("driverClass");

        Class.forName(driverClass);
        Connection connection = DriverManager.getConnection(url,user,password);
        System.out.println("connection = " + connection);
    }
}
